import { defineStore } from 'pinia'
import axios from 'axios'

export const useAuthStore = defineStore('auth', {
  state: () => ({
    user: null,
    isAuthenticated: false
  }),
  
  actions: {
    async loginUser(userData) {
      try {
        const response = await axios.post('/auth/login', userData)
        if (response.data.success) {
          this.user = userData
          this.isAuthenticated = true
          return true
        }
        return false
      } catch (error) {
        console.error('Login error:', error)
        return false
      }
    },

    async registerUser(userData) {
      try {
        const response = await axios.post('/auth/register', userData)
        return response.data.success
      } catch (error) {
        console.error('Register error:', error)
        return false
      }
    },

    logout() {
      this.user = null
      this.isAuthenticated = false
    }
  }
}) 